package com.hopu.controller.packing;

import com.hopu.domain.packing.PackingListC;
import com.hopu.service.PackingListCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/packinglist")
/**
 * 装箱模块
 */
public class PackingListController {

    @Autowired
    PackingListCService packingListService;


    /*@RequestMapping("/cargo/packinglist/tocreate.action")
    public String tocreate(String[] id, Model model){			//出口报运的id集合
        //携带出口报运的id集合	//显示装箱和报运的关系
        model.addAttribute("divData", packingListService.getDivDataCreate(id));
        return "/cargo/packinglist/jPackingListCreate";
    }

    @RequestMapping("/cargo/packinglist/insert.action")
    public String insert(PackingList packingList){
        packingListService.insert(packingList);
        return "redirect:/cargo/packinglist/list.action";
    }*/
    //去修改页面：
   /* @RequestMapping("/cargo/packinglist/toupdate.action")
    public String toupdate(String id, Model model){
        PackingList obj = packingListService.get(id);
        System.out.println(obj);
        model.addAttribute("obj", obj);
        String _s = packingListService.getDivDataUpdate(obj.getExportIds().split("\\|"), obj.getExportNos().split("\\|"));
        model.addAttribute("divData", _s);
        return "/cargo/packinglist/jPackingListUpdate";
    }

    //真正修改
    @RequestMapping("/update")
    public String update(PackingListC packingListC){
        packingListService.update(packingListC);
        return "redirect:list";
    }*/

    @RequestMapping("toview")
    public String toview(String packingListId, Model model){
        PackingListC packingListC = packingListService.selectById(packingListId);
        model.addAttribute("obj",packingListC);
//        model.addAttribute("divData", packingListService.getDivDataView(obj.getExportNos().split("\\|")));
        return "/cargo/packinglist/jPackingListView";
    }

    @RequestMapping("delete")
    public String delete(String [] packingListId){
        packingListService.delete(packingListId);
        return "redirect:list";
    }

    @RequestMapping("list")
    public String list(Model model){
        List<PackingListC> packingListCS = packingListService.selectByExample();

        model.addAttribute("dataList", packingListCS);
        return "/cargo/packinglist/jPackingListList";
    }

    @RequestMapping("/submit")
    public String submit(String[] packingListId, Map<String, Object> map){
        if (packingListId != null) {
            for (String fid : packingListId) {
                map.put("packingListId",fid);
                Integer i = 1;
                map.put("state",i);
                packingListService.state(map);
            }
        }
        return "redirect:list";
    }
    @RequestMapping("/cancel")
    public String cancel(String[] packingListId, Map<String, Object> map){
        if (packingListId != null) {
            for (String fid : packingListId) {
                map.put("packingListId",fid);
                Integer i = 0;
                map.put("state",i);
                packingListService.state(map);
            }
        }
        return "redirect:list";
    }
}
